## Script (Python) "plonifyActions"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=template_id, actions=None, default_tab='view'
##title=
##
# Use the KE plonifyActions script when inside a Model
if hasattr(context.aq_explicit, 'isInstanceOf'):
    return context.GenericObject_plonifyActions(template_id,actions=actions,default_tab=default_tab)


here_url = context.absolute_url()
site_properties=context.portal_properties.site_properties

if actions is None:
    actions=context.portal_actions.listFilteredActionsFor()

actionlist=[]
if same_type(actions, {}):
    fti = context.getTypeInfo()
    if fti and fti.getId() in site_properties.use_folder_tabs:
        actionlist=actions['folder']+actions['object']+actions.get('object_tabs',[])
    else:
        actionlist=actions['object']+actions.get('object_tabs',[])



plone_actions=[]
use_default=1
for action in actionlist:
    item={'name':'',
          'title':'',
          'id':'',
          'url':'',
          'selected':''}

    #if action['title'] == 'Contents': continue
    
    item['name']=action['name']
    item['title']=action['name'] # Plone 2.5 compat
    item['id']=actionid=action['id']

    aurl=action['url'].strip()
    if not (aurl.startswith('http') or aurl.startswith('javascript')):
        item['url']='%s/%s'%(here_url,aurl)
    else:
        item['url']=aurl

    #KNOWLEDGEENGINEE: HACK HERE TO CHECK FOR SOMETHING THAT SOUNDS LIKE 'folder_contents'
    if template_id.rfind(item['url'].split('/')[-1]) >= 0 and use_default:
        item['selected']=1
        use_default=0

    plone_actions.append(item)

if use_default:
    for action in plone_actions:
        if action['id']==default_tab:
            action['selected']=1
            break

return plone_actions
